<?php
	/**
	* Video manager Edit page
	* @author trungdt
	* @since Oct 26, 2011 
	* 
	* Change logs
	* 
	*/

	if (!defined('EXPONENT')) exit('');
	
	$video = null;
	$config=null;
	if (isset($_GET['id'])) {
		$video = $db->selectObject('productsmodule_video','id='.intval($_GET['id']));
		$config=null;
		if ($video) {
			$loc = unserialize($video->location_data);
		}
	}
	
	$config = $db->selectObject('productsmodule_config',"location_data='".serialize($loc)."'");
	
	if ($config == null) {
		$params=array();
		$params['module']=$loc->mod;
		$params['action']='configure';
		$params['src']=$loc->src;
		$params['_common']=1;
		$video=exponent_core_makeLink($params);
		header("Location: {$video}");
		die();
	}

	if (exponent_permissions_check(array('administrate','configure', "create", "edit"),$loc)) {
		$form = productsmodule_categories::video_form($video,$config);
		$form->location($loc);
		$form->meta('action','video_save');

		$template = new template('productsmodule','_video_edit');
		$template->assign('is_edit',(isset($video->id)? 1 : 0));
		$template->assign('form_html',$form->toHTML());
		$template->output();
	} else {
		echo SITE_404_HTML;
	}

?>